﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BanditGame2.WCFService;

namespace BanditGame2
{
    public partial class QuestionWindow : ChildWindow
    {
        bool isCorrect = false;

        public QuestionWindow(Question question, List<Answer> answers, bool hint)
        {
            InitializeComponent();
            

            tbQuestionLvl.Text = "Úroveň otázky: " + question.Lvl;
            tbQuestionText.Text = question.Text;
            int remove = 2;

            if (!hint)
            {
                foreach (Answer answer in answers)
                {
                    RadioButton rb = new RadioButton();
                    rb.Content = answer.Text;
                    rb.GroupName = "rbAnswers";
                    rb.Tag = answer.Correct;
                    rb.Checked += rb_OnChecked;
                    stackPanel.Children.Add(rb);
                }    
            }
            else
            {
                foreach (Answer answer in answers)
                {
                    if (answer.Correct)
                    {
                        RadioButton rb = new RadioButton();
                        rb.Content = answer.Text;
                        rb.GroupName = "rbAnswers";
                        rb.Tag = answer.Correct;
                        rb.Checked += rb_OnChecked;
                        stackPanel.Children.Add(rb);
                    } 
                    else if (remove > 0)
                    {
                        remove--;
                    }
                    else
                    {
                        RadioButton rb = new RadioButton();
                        rb.Content = answer.Text;
                        rb.GroupName = "rbAnswers";
                        rb.Tag = answer.Correct;
                        rb.Checked += rb_OnChecked;
                        stackPanel.Children.Add(rb);
                    }
                }    
 
            }
            
        }
        
        void rb_OnChecked(object sender, RoutedEventArgs e)
        {
            RadioButton rb = sender as RadioButton;
            isCorrect = (bool) rb.Tag;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (isCorrect)
            {   
                //MessageBox.Show("CORRECT");
                this.DialogResult = true;
            }
            else
            {
                MessageBox.Show("INCORRECT");
                this.DialogResult = false;
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

